//
//  loginContentViewController.m
//  PostMessa
//
//  Created by never down on 15-6-2.
//  Copyright (c) 2015年 ygy_ios. All rights reserved.
//

#import "loginContentViewController.h"
#import "PostMessa-Prefix.pch"
@interface loginContentViewController () <UITextFieldDelegate>{
    UIView *navView;
}
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (weak, nonatomic) IBOutlet UIButton *LoginBtn;

@end

@implementation loginContentViewController

//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    return self;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //监听键盘事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

}


#pragma mark - action
- (void)keyboardWillShow:(NSNotification *)notification{
    CGFloat height = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
//    height = height + _LoginBtn.frame.origin.y + _LoginBtn.frame.size.height +
}

- (void)keyboardWillHide:(NSNotification *)notification{
    
}

- (IBAction)loginBtnSubmit:(id)sender {
    
}

- (IBAction)forgetBtnSub:(id)sender {
    
}

- (IBAction)registerBtnSub:(id)sender {
    
}
#define LINEMARGIN 10

- (void)initUI{
    navView = [[UIView alloc] initWithFrame:CGRectMake(0, STATUSHEIGHT, WIDTH, NAVBARHEIGHT)];
    [self.view addSubview: navView];
    
    UIImage *img = [UIImage imageNamed:@"arrow-back.png"];
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0 ,img.size.width + LINEMARGIN * 2 , NAVBARHEIGHT)];
    [backBtn setImage:img forState:UIControlStateNormal];
    [backBtn setImageEdgeInsets:UIEdgeInsetsMake(0,LINEMARGIN,0 ,LINEMARGIN )];
    [backBtn addTarget:self action:@selector(backToMain) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
}


- (void)backToMain{
//    CATransition *transition = [CATransition animation];
//    transition.type = kCATransitionPush;
////    transition.duration = 0.2f;
//    transition.subtype = kCATransitionFromLeft;
//    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    //    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

    [self dismissViewControllerAnimated:YES completion:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"backToHome" object:@"0"];
}

#pragma mark - textFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillShowNotification object:nil];
}


#pragma mark -
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [_username resignFirstResponder];
    [_password resignFirstResponder];
}


@end
